[VB]分前后半段及指定档案问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 07:14:59
[img]http://flypicture.com/files/MjIyODI2[/img]
要做成这样子数字要整数 考试的时候会有100个数字不过上限也要设定为100个 然后在记事本输入像
76
24
19
81
77
63
54
88
然后比第5个大的前半段数字加起来 在此就是76+81 老师会在C槽放很多记事本要我们打上档名 就会有结果出来
-------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
ReDim ary(100) As Integer
Open "c:\in.txt" For Input As #2
Do While Not EOF(2) 'eof=End Of File
Input #2, s
If ary(s) = ary(3) Then
ary(i) = Val(s)
i = i + 1
End If

Loop
Close #2
ReDim Preserve ary(i - 1) 'redim后加阵列消失 若保留+preserve
For i = 0 To UBound(ary)
s1 = s1 + ary(i) '总合
Next i
Open "c:\out.txt" For Output As #3
For i = 0 To UBound(ary)
Print #3, Trim(ary(i))
Next i
Print #3, "总合:"

国语真得不好懂唉!

假定你的档案名是在text1文本框中输入的,打开时就是
open text1.text for [input/output/append] as #2

=======re: 补充问题=============
如果你的档案文件是你的输入文件:
将open text1.text for input as #2
替换你代码中的
Open "c:\in.txt" For Input As #2
如果你的档案文件是你的输出文件则用
open text1.text for output as #3
替换你的代码中的
Open "c:\out.txt" For Output As #3

不甚明了,能再说清楚点么?

C槽是什么?
看图片不是本地人啊

还有用数据库将会非常容易,用纯文本文件麻烦一个说